import { App, PluginSettingTab, Setting } from "obsidian";
import AutoUploadPlugin from "./main";

// 定义插件里需要保存、用到的变量
export interface MyPluginSettings {
	uploadAddress: string;
}

// 定义 DEFAULT_SETTINGS 并使用接口设置（DEFAULT_SETTINGS会在后边的插件主功能中的“loadSettings”（加载设置）中用到）
export const DEFAULT_SETTINGS: MyPluginSettings = {
	uploadAddress: ""
}
// 插件设置页面
export class MySettingTab extends PluginSettingTab {
	plugin: AutoUploadPlugin;

	constructor(app: App, plugin: AutoUploadPlugin) {
		super(app, plugin);
		this.plugin = plugin;
	}

	display(): void {
		const {containerEl} = this;

		containerEl.empty();

		// 新建一个h2元素当标题
		containerEl.createEl('h2', {text: 'Auto upload plguin setting'});

		// 新建一个设置选项
		new Setting(containerEl)
			.setName('Setting upload address')
			.setDesc('It\'s a url and returns the access url after uploading')
			.addText(text => text
				.setPlaceholder('Enter your url')
				.setValue(this.plugin.settings.uploadAddress)
				.onChange(async (value) => {
					console.log('upload url: ' + value);
					this.plugin.settings.uploadAddress = value;
					console.log(this.plugin.settings.uploadAddress);
					await this.plugin.saveSettings();
				}));
	}
}